package io.renren.controller;

import io.renren.entity.*;
import io.renren.service.CheckCodeService;
import io.renren.vo.RespModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/checkcode")
@Api(tags="短信验证")
public class CheckCodeController {

    @Autowired
    private CheckCodeService checkCodeService;

	/**
	 * 生成短信验证码
	 * 
	 * @return
	 */
	@PostMapping(value = "gen/sms",consumes = MediaType.APPLICATION_JSON_VALUE,
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "发送短信验证码" ,consumes = MediaType.APPLICATION_JSON_VALUE,produces = MediaType.APPLICATION_JSON_VALUE)
	@com.cxytiandi.encrypt.springboot.annotation.Decrypt
	@com.cxytiandi.encrypt.springboot.annotation.Encrypt
	public RespModel<SmsCheckCodeOutputModel> generateSmsCode(@RequestBody SmsCheckCodeInputModel smsCheckCodeInputModel){
        return checkCodeService.generateSmsCode(smsCheckCodeInputModel);
    }

	/**
	 * 生成短信验证码
	 *  httpclient 方式生成短信验证码
	 * @return
	 */
	@PostMapping(value="/getSmsCode", consumes = MediaType.APPLICATION_JSON_VALUE,produces = MediaType.APPLICATION_JSON_VALUE)
	@com.cxytiandi.encrypt.springboot.annotation.Decrypt
	@com.cxytiandi.encrypt.springboot.annotation.Encrypt
	public RespModel<SmsCheckCodeOutputModel> getSmsCode(@RequestBody SmsCheckCodeInputModel smsCheckCodeInputModel){
        return checkCodeService.getSmsCode(smsCheckCodeInputModel);
    }

	/**
	 * 生成图片验证码
	 *
	 * @return
	 */
	@PostMapping(value="/gen/image",consumes=MediaType.APPLICATION_JSON_VALUE,produces = MediaType.APPLICATION_JSON_VALUE)
	@com.cxytiandi.encrypt.springboot.annotation.Decrypt
	@com.cxytiandi.encrypt.springboot.annotation.Encrypt
	public RespModel<ImageCheckCodeModel> generateImageCode(@RequestBody ImageCheckCodeInputMode imageCheckCodeInputMode){
        return checkCodeService.generateImageCode(imageCheckCodeInputMode);
    }

	/**
	 * 验证验证码
	 *
	 * @param verifyCheckCodeModel
	 * @return
	 */
	@PostMapping(value="/verify",consumes = MediaType.APPLICATION_JSON_VALUE,produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value="验证短信验证码",consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
	@com.cxytiandi.encrypt.springboot.annotation.Decrypt
	@com.cxytiandi.encrypt.springboot.annotation.Encrypt
	public RespModel<String> verifyCheckCode(@RequestBody VerifyCheckCodeInputModel verifyCheckCodeModel){
        return checkCodeService.verifyCheckCode(verifyCheckCodeModel);
    }

}
